home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / ARASAN_S.ZIP / EMOVE.CPP < prev    next >
C/C++ Source or Header  |  1994-02-19  |  3KB  |  142 lines

  1. // Copyright 1994 by Jon Dart.  All Rights Reserved.
  2.  
  3. #include "emove.h"
  4. #include "util.h"
  5. extern "C"
  6. {
  7. #include <string.h>
  8. };
  9.  
  10. ExtendedMove::ExtendedMove() 
  11. {
  12.     MakeNull();
  13. }
  14.  
  15. void ExtendedMove::set_special(const Board &ABoard)
  16. {
  17.     // set special field
  18.     my_special = Normal;
  19.     switch (my_piecemoved.Type())
  20.     {
  21.     case Piece::Pawn:
  22.        if (my_dest.Rank(ABoard.Side()) == 8)
  23.        {
  24.           my_special = Promotion;
  25.       //my_promotion = Piece(Piece::Queen,ABoard.Side()); // for now
  26.        }
  27.        else if (ABoard[my_dest].IsEmpty())
  28.        {
  29.           if (my_dest.File() != my_start.File())
  30.       {
  31.          my_special = (byte)EnPassant;
  32.          my_capture = Piece(Piece::Pawn,ABoard.OppositeSide());
  33.       }
  34.        }
  35.        break;
  36.     case Piece::King:
  37.        if (Util::Abs((int)my_start - (int)my_dest) == 2)
  38.        {
  39.           if (my_start > my_dest)
  40.          my_special = QCastle;
  41.           else
  42.          my_special = KCastle;
  43.        }
  44.        break;
  45.     default:
  46.        break;
  47.     }
  48. }
  49.  
  50. ExtendedMove::ExtendedMove( const Board &ABoard, const Square start, 
  51.   const Square dest, const Piece::PieceType promotion )
  52. : Move(start,dest,promotion)
  53. {
  54.      if (start == Square::InvalidSquare)
  55.     my_piecemoved = Piece::InvalidPiece();
  56.      else
  57.     my_piecemoved = ABoard[start];
  58.      if (dest == Square::InvalidSquare)
  59.     my_capture = Piece::InvalidPiece();
  60.      else
  61.     my_capture = ABoard[dest];
  62.      set_special(ABoard);
  63. }
  64.  
  65. ExtendedMove::ExtendedMove( const Board &ABoard, const Move &move )
  66. : Move(move.StartSquare(), move.DestSquare(), move.PromoteTo())
  67. {
  68.      if (move.StartSquare() == Square::InvalidSquare)
  69.     my_piecemoved = Piece::InvalidPiece();
  70.      else
  71.     my_piecemoved = ABoard[move.StartSquare()];
  72.      if (move.DestSquare() == Square::InvalidSquare)
  73.     my_capture = Piece::InvalidPiece();
  74.      else
  75.     my_capture = ABoard[move.DestSquare()];
  76.      set_special(ABoard);
  77. }
  78.  
  79. const int ExtendedMove::operator == (const ExtendedMove &m) const
  80. {
  81.    return (Move::operator == (m)) &&
  82.           (my_special == m.my_special) &&
  83.       (my_piecemoved == m.my_piecemoved) &&
  84.       (my_capture == m.my_capture);
  85. }
  86.         
  87. void ExtendedMove::MakeNull()
  88. {
  89.    Move::MakeNull();
  90.    my_special = Normal;
  91.    my_capture = my_piecemoved = Piece::InvalidPiece();
  92. }
  93.  
  94. const ExtendedMove::SpecialType ExtendedMove::Special() const
  95. {
  96.     return (SpecialType)my_special;
  97. }
  98.  
  99. static char FileImage( const Square sq )
  100. {
  101.     return 'a' + sq.File() - 1;
  102. }
  103.  
  104. static char RankImage( const Square sq )
  105. {
  106.     return '1' + sq.Rank(White) - 1;
  107. }
  108.  
  109. const char * ExtendedMove::Image() const
  110. {
  111.     static char image[10];
  112.     if (IsNull())
  113.        return Move::Image();
  114.     if (Special() == KCastle)
  115.     {
  116.           strcpy(image,"o-o");
  117.       return image;
  118.     }
  119.     else if (Special() == QCastle)
  120.     {
  121.       strcpy(image,"o-o-o");
  122.       return image;
  123.     }
  124.     image[0] = FileImage(StartSquare());
  125.     image[1] = RankImage(StartSquare());
  126.     if (Capture().IsEmpty())
  127.        image[2] = '-';
  128.     else
  129.        image[2] = 'x';
  130.     image[3] = FileImage(DestSquare());
  131.     image[4] = RankImage(DestSquare());
  132.     int i = 5;
  133.     if (my_promotion != Piece::Empty && my_promotion != Piece::Invalid)
  134.     {
  135.        image[i++] = '=';
  136.        image[i++] = Piece::Image(my_promotion);
  137.     }
  138.     image[i] = '\0';
  139.     return image;
  140. }
  141.  
  142.